package fr.utbm.aiechat.packets;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class UserFileResponsePacket
{
	private ByteArrayOutputStream stream;

	public UserFileResponsePacket(String filename, long size, byte[] buffer)
	{
		stream = new ByteArrayOutputStream();
		try
		{
			DataOutputStream dataObj = new DataOutputStream(stream);
			
			dataObj.writeInt(Packets.USERFILE_RESPONSE);
			
			dataObj.writeUTF(filename);
			
			dataObj.writeLong(size);
			
			dataObj.write(buffer);
			
			dataObj.flush();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public byte[] getPacket()
	{
		return stream.toByteArray();
	}
}
